package com.huawei.appgallery.wishlist.control;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.text.format.DateUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.huawei.appgallery.wishlist.api.WishInfo;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.util.ArrayList;
import java.util.List;
import o.azb;
import o.dce.c;
import o.dce.i;
import o.dce.j;
import o.dch;
import o.dof;
import o.ContentManager;
import o.epv;
import o.CollectCheck;
import o.MinimumFactory;

public class WishListAdapter extends BaseAdapter {
    private static final int ARROW_VIEW_WITHD = 12;
    private static final int CONTENT_LAYOUT_PADDING = 32;
    private static final int DRAWABLE_PADDING = 8;
    private static final int SCREEN_SPLIT_COUNT = 3;
    private static final String TAG = "WishListAdapter";
    private Activity mActivity;
    private LayoutInflater mInflater;
    private List<WishInfo> wishList = new ArrayList();

    static class e {
        private TextView ˋ;
        private TextView ˏ;
        private TextView ॱ;

        private e() {
        }

        private TextView ॱ() {
            return this.ˋ;
        }

        private void ˏ(TextView textView) {
            this.ˋ = textView;
        }

        private TextView ˏ() {
            return this.ˏ;
        }

        private void ॱ(TextView textView) {
            this.ˏ = textView;
        }

        private TextView ˎ() {
            return this.ॱ;
        }

        private void ˋ(TextView textView) {
            this.ॱ = textView;
        }
    }

    public WishListAdapter(Activity activity, int i) {
        this.mActivity = activity;
        this.mInflater = LayoutInflater.from(getmActivity());
    }

    public View getView(int i, View view, ViewGroup viewGroup) {
        WishInfo itemWishInfo = getItemWishInfo(i);
        if (itemWishInfo != null) {
            view = initItemWishInfoView(itemWishInfo, getmInflater());
            if (this.wishList != null && this.wishList.size() - 1 == i) {
                view.findViewById(o.dce.e.ᐨ).setVisibility(4);
            }
        }
        return view;
    }

    private View initItemWishInfoView(WishInfo wishInfo, LayoutInflater layoutInflater) {
        if (wishInfo == null) {
            return null;
        }
        View inflate = layoutInflater.inflate(i.ˏ, null);
        azb.ˏ(inflate);
        e initWishInfoHolder = initWishInfoHolder(inflate);
        if (1 == wishInfo.ᐝ()) {
            Drawable drawable = this.mActivity.getResources().getDrawable(c.ॱ);
            drawable.setBounds(0, 0, epv.ˋ(this.mActivity, 8), epv.ˋ(this.mActivity, 8));
            if (MinimumFactory.getBoolValue(ContentManager.getInstant().getContext())) {
                initWishInfoHolder.ॱ().setCompoundDrawables(drawable, null, null, null);
            } else {
                initWishInfoHolder.ॱ().setCompoundDrawables(null, null, drawable, null);
            }
            initWishInfoHolder.ॱ().setCompoundDrawablePadding(epv.ˋ(this.mActivity, 8));
        } else {
            initWishInfoHolder.ॱ().setCompoundDrawables(null, null, null, null);
        }
        initWishInfoHolder.ॱ().setText(wishInfo.ˊ());
        String string = ContentManager.getInstant().getContext().getString(j.ˏॱ);
        String ˎ = wishInfo.ˎ();
        String str = "";
        if (!dof.ॱ(ˎ)) {
            str = formateCreateDate(ˎ);
        }
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(string).append(HwAccountConstants.BLANK).append(str);
        initWishInfoHolder.ˏ().setText(stringBuilder.toString());
        initWishInfoHolder.ˎ().setText(wishInfo.ॱ());
        return inflate;
    }

    private String formateCreateDate(String str) {
        Long valueOf = Long.valueOf(0);
        try {
            valueOf = Long.valueOf(Long.parseLong(str));
        } catch (NumberFormatException e) {
            dch.ˎ.ˊ(TAG, "get createDate error: " + e.toString());
        }
        if (valueOf.longValue() == 0) {
            return "";
        }
        return DateUtils.formatDateTime(this.mActivity, valueOf.longValue(), 131092);
    }

    private e initWishInfoHolder(View view) {
        e eVar = new e();
        TextView textView = (TextView) view.findViewById(o.dce.e.ʼˊ);
        TextView textView2 = (TextView) view.findViewById(o.dce.e.ʽˋ);
        eVar.ˏ((TextView) view.findViewById(o.dce.e.ʻˊ));
        eVar.ॱ(textView);
        eVar.ˋ(textView2);
        return eVar;
    }

    public Object getItem(int i) {
        return getWishList().get(i);
    }

    public long getItemId(int i) {
        return (long) i;
    }

    private WishInfo getItemWishInfo(int i) {
        if (CollectCheck.isEmpty(getWishList()) || i >= getWishList().size()) {
            return null;
        }
        return (WishInfo) getWishList().get(i);
    }

    public void clearCache() {
        if (!CollectCheck.isEmpty(getWishList())) {
            getWishList().clear();
        }
    }

    public void addData(WishInfo wishInfo) {
        getWishList().add(wishInfo);
    }

    public boolean isWishListEmpty() {
        return getWishList().isEmpty();
    }

    public int getCount() {
        if (CollectCheck.isEmpty(getWishList())) {
            return 0;
        }
        return getWishList().size();
    }

    private List<WishInfo> getWishList() {
        return this.wishList;
    }

    public void setWishList(List<WishInfo> list) {
        this.wishList.clear();
        this.wishList.addAll(list);
    }

    private LayoutInflater getmInflater() {
        return this.mInflater;
    }

    private Activity getmActivity() {
        return this.mActivity;
    }

    public void setmActivity(Activity activity) {
        this.mActivity = activity;
    }
}
